export default class orc_loading extends Laya.Script {
  
    constructor() { super(); }

    async onAwake(){
        //1.读取网络配置
        let body = [];  
        if(Laya.Browser.onMiniGame)
        {
            orc.log('weixin env');
            body["platform_id"] = "1";  //0-测试环境TEST 1.微信:WX 2.oppo:OPPO 3.vivo:VIVO 4.抖音:DOUYIN
            orc.orc_config.PLATFORM = 'WX';            
            orc.orc_data.memory_data.user_guest = false;
        }
        else if(Laya.Browser.onMobile)
        {
            orc.log('test env');
            body["platform_id"] = "0";  //0-测试环境TEST 1.微信:WX 2.oppo:OPPO 3.vivo:VIVO 4.抖音:DOUYIN
            orc.orc_config.PLATFORM = 'TEST';      
        }
        body["game_tag"] = orc.orc_config.GAME_NAME;
        body["time"] =Math.floor(new Date().getTime()/1000);

        let result = await orc.orc_net.http_post(orc.orc_url_config.game_config,body);
        //2.读取本地存储
        orc.orc_data.load_local_data();
        //3.相关事件注册        
        orc.event_manager.add_listener(orc.event_id.orc_res_event,this.orc_res_event.bind(this));               
        //4.加载相关的预制体       
        orc.res_manager.res_pkg["prefabs"] = [
            "prefabs/common/alert_tip.json",
            "prefabs/common/loading_tip.json",
            "prefabs/win/win_home.json",
        ];
        orc.res_manager.preload_res_pkg();
        //5.读取设备的分辨率，做相应的适配 
        let bg_height:Laya.Sprite = this.owner as Laya.Sprite;
        bg_height.height = Laya.stage.height;
        orc.log(Laya.stage.height);
    }

    //资源加载完成
    orc_res_event(){       
        // Laya.Scene.open("test_scene.scene");     
        orc.log('orc_res_event');
        Laya.stage.getChildByName('root').getChildAt(0).getChildByName('win_loading').removeSelf();
       
        orc.prefab_manager.win_open('win_home');
    }

    onEnable(): void {
        
    }

    onDisable(): void {
    }

    onUpdate(){
        let progress_value:Laya.ProgressBar = this.owner.getChildByName('progress_bar') as Laya.ProgressBar;
        
        progress_value.value = orc.res_manager.now_num / orc.res_manager.total_num;
    }
}